home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / ABox 1.9.5 / CPlus Files / ABUString.c < prev    next >
Encoding:
Text File  |  1995-10-26  |  5.1 KB  |  227 lines  |  [TEXT/MMCC]

  1. /*    
  2.     Copyright © 1991-1995 by TopSoft Inc.  All rights reserved.
  3.  
  4.     You may distribute this file under the terms of the TopSoft
  5.     Artistic License, accompanying this package.
  6.     
  7.     This file was developed by George (ty) Tempel in connection with TopSoft, Inc..
  8.     See the Modification History for more details.
  9.  
  10. Product
  11.     About Box
  12.  
  13. FILE
  14.     ABUString.c
  15.  
  16. NAME
  17.     ABUString.c, part of the ABox project source code,
  18.     responsible for mix-in handling the AboutBox string stuff.
  19.  
  20. DESCRIPTION
  21.     This file contains defines for the about box modules.
  22.     
  23. DEVELOPED BY
  24.     George (ty) Tempel                ttempel@monmouth.com
  25.     All code in this file, and its associated header file was
  26.     Created by George (ty) Tempel in connection with the TopSoft, Inc.
  27.     "FilterTop" application development, except where noted.
  28.     
  29.     This file is based, in part, upon prior work by
  30.     Greg Anderson <greggor@apple.com> of Apple DTS.
  31.  
  32.  
  33. CARETAKER - George (ty) Tempel <ttempel@monmouth.com>
  34.      Please consult this person for any changes or suggestions to this file.
  35.  
  36. MODIFICATION HISTORY
  37.  
  38.     dd mmm yy    -    xxx    -    patchxx: description of patch
  39.     10 June 94    -    ty    -    Initial Version Created
  40.     20-july-94    -    ty    -    initial version released
  41.     23-may-95    -    ty    -    changes for compatibility with the CodeWarrior CW6
  42.                             release and the associated Universal Headers from Apple:
  43.                             most methods that returned references now have "Ref" at
  44.                             the end of their methods names to prevent possible collisions
  45.                             with datatypes and classes of the same name (older versions
  46.                             of the compiler didn't have a problem with this).
  47.     25-oct-95    -    ty    -    changes for "const" usage under CW7; simplification of Boolean
  48.                             query methods
  49.  
  50. */
  51.  
  52. /*==============================================================================*/
  53.  
  54. /*======= Segmentation directives ========*/
  55.  
  56. //#pragma segment ty
  57.  
  58. /*============ Header files ==============*/
  59.  
  60. #include     "ABUString.h"
  61. #include    "ABoxDefs.h"
  62.  
  63. /*=============== Globals ================*/
  64.  
  65.  
  66. /*================ CODE ==================*/
  67.  
  68.  
  69. /*=============== Globals ================*/
  70.  
  71.  
  72. /*================ CODE ==================*/
  73.  
  74.  
  75. /*=============================== ABUString::ABUString ================================*/
  76. ABUString::ABUString(void)
  77. {
  78. }    // end ABUString
  79.  
  80.  
  81. /*=============================== ABUString::~ABUString ================================*/
  82. ABUString::~ABUString(void)
  83. {
  84. }    // end ~ABUString
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91. /*=============================== ABUString::P2Ccpy ==================================*/
  92. //
  93. //    Copy a pascal style string into a C string; if either parameter
  94. //    is bad the routine does nothing.
  95. //
  96. void    ABUString::P2Ccpy(char *c, Str255 p)
  97. {
  98.     short    index;
  99.     
  100.     //    begin here...
  101.     
  102.     if (!(c && p))
  103.         return;
  104.     else
  105.         index = p[0];
  106.     
  107.     //    copy from back to front
  108.     c[index] = '\0';
  109.     
  110.     while (index > 0)
  111.     {
  112.         c[index - 1] = p[index];    //    pascal strings _start_ w/length byte
  113.         --index;
  114.     } // end while loop
  115.     
  116. } // end P2Ccpy
  117.  
  118.  
  119.  
  120. /*=============================== ABUString::C2Pcpy ==================================*/
  121. //
  122. //    Copy a C string into a Pascal string; if either parameter
  123. //    is bad the routine does nothing.
  124. //
  125. void    ABUString::C2Pcpy(Str255 p, char *c)
  126. {
  127.     short    index = 0;
  128.     
  129.     const short    kPMax = 255;        //    max length of an Str255
  130.     
  131.     //    begin here...
  132.     
  133.     if (!(c && p))
  134.         return;
  135.     
  136.     while((*c) && (index < kPMax))
  137.         p[index++] = *c++;
  138.     p[0] = index - 1;
  139. }    //    end of C2Pcpy
  140.  
  141.  
  142. /*=============================== ABUString::PCcmp ==================================*/
  143. //
  144. //    Compare a Pascal string with a C string, returning the same values
  145. //    that strcmp() would if we were dealing with strictly C-style strings.
  146. //
  147. short ABUString::PCcmp(Str255 p, char *c)
  148. {
  149.     Str255        tempString;
  150.     short        result;
  151.     
  152.     //    begin here...
  153.     if (!(p && c))
  154.     {
  155.         if (p && !c)
  156.             return 1;
  157.         else if (!p && c)
  158.             return -1;
  159.         else
  160.             return 0;
  161.     } 
  162.     else 
  163.     {    
  164.         C2Pcpy(tempString, c);
  165.         result = EqualString(p, tempString, kABcaseInsensitive, kABdiacriticalInsensitive);    // in OSUtils.h
  166.         return result;
  167.     } // end if else block
  168. }    //    end PCcmp()
  169.  
  170.  
  171.  
  172.  
  173.  
  174. /*=============================== ABUString::P2Pstrcat ==================================*/
  175. //
  176. //    Copy a Pascal string onto the tail end of another (append), returning the 
  177. //    newly created string.
  178. //
  179. //    Any problems with the parameters is reflected in the output string; if
  180. //    both inputs are bad, the output is NULL; if the source is bad, the
  181. //    output is the destination string; if the destination is bad, the output
  182. //    is the source.
  183. //
  184. StringPtr ABUString::P2Pstrcat(Str255 dest, Str255 src)
  185. {
  186.     unsigned char        *destPtr;
  187.     unsigned char        *srcPtr;
  188.     unsigned char        *tPtr;
  189.     short                index;
  190.     short                max;
  191.     const short            kPMax = sizeof(Str255);        //    max length of an Str255
  192.     
  193.     //    begin here...
  194.     
  195.     if (!(dest && src))
  196.         if (dest && !src)
  197.             return dest;
  198.         else if (!dest && src)
  199.             return src;
  200.         else
  201.             return NULL;
  202.     
  203.     srcPtr = (unsigned char*) src;
  204.     destPtr = (unsigned char*) dest;
  205.     max = *srcPtr;
  206.     
  207.     // Adjust past length & chars already in dest
  208.  
  209.     tPtr = destPtr + *destPtr + 1;
  210.     ++srcPtr;
  211.  
  212.     // Determine how many characters we can really copy
  213.  
  214.     if(max + *destPtr > kPMax)
  215.         max = kPMax - *destPtr;
  216.     *destPtr += max;
  217.     
  218.     for(index = 0; index < max ; ++index)
  219.         *tPtr++ = *srcPtr++;
  220.     
  221.     return dest;
  222.     
  223. }    //    end of P2Pstrcat()
  224.  
  225.  
  226. //    end of file.
  227.